<?php
    $store = Mage::app()->getStore();
    $code  = $store->getCode();
?>
<script type="text/javascript">
//<![CDATA[
var dailydealTimeCounters = new Array();
var i = 0;
//]]>
</script>
<div class="block block-dailydeal-new">
    <div class="block-title"><strong><span><?php echo $this->getTitle() ? $this->getTitle() : $this->__('Daily Deal'); ?></strong></span></div>
	<div class="block-content">
	<?php
	$deals       = $this->getSidebarDeals();
	$_coreHelper = $this->helper('core');
	$_helper     = $this->helper('catalog/output');
	?>
	<?php if (!$deals->count()): ?>
		<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
	<?php else: ?>
		<div class="products small-list sidebar-list ">
			<?php $_iterator = 0; ?>
			<?php $count = 0;
			foreach ($deals as $_product): ?>
				<?php $deal = $this->getDealByProduct($_product->getEntityId()); ?>
				<?php if (!$deal->getId()) continue; ?>
			<div class="sidebardailydeal item">
				<div class="item-area">
					<div class="product-image-area">
						<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
							<img src="<?php if(Mage::getStoreConfig("porto_settings/category/aspect_ratio",$code)):?><?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(300);?><?php else: ?><?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(Mage::getStoreConfig("porto_settings/category/ratio_width",$code),Mage::getStoreConfig("porto_settings/category/ratio_height",$code)); ?><?php endif; ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"/>
                            <div class="bottom-home-dailydeal">
                                <ul class="time-left">
                                    <?php $now_time = Mage::getModel('core/date')->timestamp(time()) ?>
                                    <?php
                                    $end_time = Mage::getModel('core/date')->timestamp(strtotime($deal->getCloseTime()));
                                    ?>
                                    <div class="timeleft timeleft_<?php echo $this->getType() . $_product->getId() ?>"> </div>
                                </ul>
                            </div>
						</a>
					</div>
					<div class="details-area">
						<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_product->getName() ?>"><?php echo $deal->getTitle() ?></a></h2>
						<div class="price-box">
							<p class="old-price">
								<span class="price-label">Regular Price:</span>
								<span class="price"><?php echo $_coreHelper->currency($_product->getPrice()) ?></span>
							</p>
							<p class="special-price">
								<span class="price-label">Special Price</span>
								<span class="price"><?php echo $_coreHelper->currency($deal->getDealPrice()); ?></span>
							</p>
						</div>
					</div>
					<div class="clearer"></div>
				</div>
			</div>
			<script type="text/javascript">
			//<![CDATA[
			dailydealTimeCounters[i] = new DailydealTimeCounter('<?php echo $now_time ?>', '<?php echo $end_time ?>', '<?php echo $deal->getId() ?>');
			dailydealTimeCounters[i].setTimeleft('timeleft_<?php echo $this->getType() . $_product->getId() ?>');
			//]]>
			</script>
				<?php endforeach; ?>
		</div>
	<?php endif; ?>
	</div>
	<script type="text/javascript">decorateGeneric($$('.block-dailydeal .sidebardailydeal'), ['odd', 'even', 'first', 'last'])</script>
	<script type="text/javascript">
		jQuery(function($){
			$(".block.block-dailydeal-new .block-title").click(function(){
				if($(this).hasClass("closed")){
					$(".block.block-dailydeal-new .block-content").slideDown();
					$(this).removeClass("closed");
				} else {
					$(".block.block-dailydeal-new .block-content").slideUp();
					$(this).addClass("closed");
				}
			});
		});
	</script>
</div>
